package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Check;
import cn.wolfcode.crm.query.CheckQueryObject;
import cn.wolfcode.crm.service.ICheckService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("check")
public class CheckController {

    @Autowired
    private ICheckService checkService;

    @RequestMapping("")
    public String index(){
        return "check/list";
    }

    @RequestMapping("list")
    @ResponseBody
    public PageResult list(CheckQueryObject qo){
        return checkService.query(qo);

    }
    @RequestMapping("save")
    @ResponseBody
    public JsonResult save(Check entity){

        try{
            checkService.save(entity);

        }catch(Exception e){
            e.printStackTrace();
            return new JsonResult("保存失败");
        }

        return new JsonResult();

    }
    @RequestMapping("update")
    @ResponseBody
    public JsonResult update(Check entity){

        try{
            checkService.update(entity);

        }catch(Exception e){
            e.printStackTrace();
            return new JsonResult("修改失败");
        }
        System.out.println();


        return new JsonResult();

    }
    @RequestMapping("delete")
    @ResponseBody
    public JsonResult delete(Long id){
        if(id != null){
        try{
            checkService.delete(id);

        }catch(Exception e){
            e.printStackTrace();
            return new JsonResult("删除失败");
        }
        }

        return new JsonResult();

    }

    @RequestMapping("pointsChange")
    public String change(){
        return "check/pointsChange";
    }





}
